﻿// JScript 文件
 //切换图片



function AlternatePhoto(obj)
{
    if(obj)
    {
        //图片路径
        var imgpath = obj.src;
        imgpath = imgpath.toLowerCase();
        var BigImgPath = imgpath.replace("small","Big");
        imgpath = imgpath.replace("small","middle");
        document.getElementById("productImage").src = imgpath;
        $("#productImage").attr("jqimg",BigImgPath);
        $("#productImage").hide().fadeIn('slow');
    }
}
//选择产品尺寸,单品页
function chooseThisSize(obj,proCode,proNum)
{
    document.getElementById("SumMoney").innerHTML = document.getElementById("Span1") != null ? document.getElementById("Span1").innerHTML:document.getElementById("SellPrice").innerHTML;
    OperStyle(obj,proCode,proNum);    
    document.getElementById("sizeSpan").innerHTML = obj.innerHTML;   
    var SelectObj = OperSelect(obj,proCode,proNum); 
    SelectObj.onchange = function(){
            var tempText = document.getElementById("Span1") != null ? document.getElementById("Span1").innerHTML:document.getElementById("SellPrice").innerHTML;
            document.getElementById("SumMoney").innerHTML = parseFloat(parseFloat(tempText)*parseInt(this.value),2);
        };       
}
//选择产品尺寸，列表搜索页
function chooseTheSize(obj,proCode,proNum)
{
    OperStyle(obj,proCode,proNum);
    OperSelect(obj,proCode,proNum); 
    
}
//操作数量选择select
var OperSelect = function(obj,proCode,proNum)
{
    var SelectObj = document.getElementById("BuyNum");
        SelectObj.options.length = 0; 
    if(proNum>10)
    {        
        for(var i=1; i<11;i++)
        {
            var varItem = new Option(i,i);
            SelectObj.options.add(varItem);
        }
    }
    else
    {
        for(var i=1;i<=proNum;i++)
        {
            var varItem = new Option(i,i);
            SelectObj.options.add(varItem);
        }
    }
    document.getElementById('yes1').onclick=null;
    $("#yes1").unbind('click');
    $("#yes1").click(function()
    {
        var urlStr = '/Shopping/Product_Add.aspx?ProductID='+proCode+'&num='+document.getElementById("BuyNum").value;
        top.location.href = urlStr;
    });
    return SelectObj;
}
//操作样式
var OperStyle = function(obj,proCode,proNum)
{
    for(var i=0;i<obj.parentNode.childNodes.length;i++)
    {
        if(obj.parentNode.childNodes[i].className == 'current')
        {
            obj.parentNode.childNodes[i].className = '';
        }
    }    
    $('#sizeSpan1').html(obj.innerHTML);
    obj.className = "current";     
}
//返回二位小数
function formatFloat(src, pos)
{
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
//交替显示两 个层
function AlternateDisplay(obj1,obj2)
{
}
//写评论,参数为产品号
function WriteComment(proCode)
{
    $.blockUI({ 
            message: $('#addComment'), css: { 
                top:  ($(window).height() - 300) /2 + 'px', 
                left: ($(window).width() - 400) /2 + 'px',
                width: '400px',height: '240px' 
            }
      }); 
    $('#yes').click(function() {             
            var tempName = escape($("#UserName").val());
            var tempTitle = escape($("#Title").val());
            var tempText = escape($("#Text").html());
            if(tempName.length<2||tempName.length>150)
            {
                alert("姓名长度在2个到150个字符之间");
                return false;
            }
            if(tempTitle.length<2||tempTitle.length>150)
            {
                alert("标题长度在2个到50个字符之间");
                return false;
            }
            if(tempText.length>1000)
            {
                alert("内容字符在1000个以内");
                return false;
            }
            this.disabled="disabled";
            this.value = '您已经评论过了';
            var UpStr = "ProCode="+escape(proCode);            
            UpStr += "&UserName="+tempName;
            UpStr += "&Title="+tempTitle;
            UpStr += "&Content="+tempText;
            // update the block message 
            $.ajax({ 
                url: '/Product/ProductCommentAdd.ashx?'+UpStr, 
                cache: false, 
                success: function(data, textStatus) {
                    $("#UserName").val("");
                    $("#Title").val("");
                    $("#Text").html("");
                     $.blockUI({ message: "<h3>您的评论已经发布成功,<br />需要我们管理员审核后才能看到！</h3><div style=\"width:100%; text-align:center;\"><input type=\"button\" value=\" 确定 \" onclick=\"$.unblockUI();\" ></div>",css:{ width: '400px',height: '120px', textAlign: 'left' } }); 
                     
                },
                error: function()
                {
                     $.blockUI({ message: "<h3>出现服务器错误,管理员会解决这个问题的！</h3><div style=\"width:100%; text-align:center;\"><input type=\"button\" value=\" 确定 \" onclick=\"$.unblockUI();\" ></div>",css:{ width: '400px',height: '120px', textAlign: 'left' } }); 
                }
            }); 
        }); 
 
        $('#no').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 
} 

function ViewDetial(obj,t)
{
    var left =  GetLeftOrTop(obj,"left")+60;
    var top = GetLeftOrTop(obj,"top");
    $(obj).mouseout( function() {
	     $("#View_commentdetial").hide();
	} );
    $("#View_commentdetial").css("position","absolute");
    $("#View_commentdetial").css("left",left+"px");
    $("#View_commentdetial").css("top",top+"px");
    var div; 
    if(t==1)
    {
        div = $("#avall").html();
    }
    if(t==2)
    {
        div = $("#Avapp").html();
    }
    if(t == 3)
    {
        div = $("#Avsnug").html();
    }
    var divsplit = div.split(",");
    var total = 0;
    for(i=0;i<divsplit.length;i++)
    {
        total = total+parseFloat(divsplit[i]);
        $("#View_commentdetial").find("span").eq(i).html(divsplit[i]);
    }
    var widthnum = 0;
    for(i=0;i<divsplit.length;i++)
    {
        widthnum = (parseFloat(divsplit[i]) * 73) / total;
        if(widthnum < 1 && widthnum>0)
            widthnum = 1;
        $("#View_commentdetial > ul> li >p").next().children().eq(i).attr("width",widthnum);
    }
    if(t==1)
    {
    $("#View_commentdetial>h3>strong").html("综合评分详情（"+total+"）");
    }
    if(t==2)
    {
    $("#View_commentdetial>h3>strong").html("外观评分详情（"+total+"）");
    }
    if(t==3)
    {
    $("#View_commentdetial>h3>strong").html("舒适度评分详情（"+total+"）");
    }
    $("#View_commentdetial").show();
}

function GetLeftOrTop(obj,strName){
    var num=0;
    do
    {
        if(strName=="left")
        {
            num += obj.offsetLeft;
        }
        else
        {
            num+= obj.offsetTop;
        }
        
        obj = obj.offsetParent;
    } while(obj.tagName!="BODY");
    return num;
}

//使用方式：shiftListItem(this)
//使用场合：左侧我查看过的列表和购特的列表
function shiftListItem(obj)
{
    if(obj)
    {
        var childnodes = obj.parentNode.childNodes;
        for(var i=0; i < childnodes.length;i++)
        {
            if(childnodes[i].nodeName.toLowerCase() == "dl")
            {
                childnodes[i].style.display = 'none';
            }
            else if(childnodes[i].nodeName.toLowerCase() == "ul")
            {
                childnodes[i].style.display = '';
            }
        }
        obj.style.display = 'none';
        if(document.all)
        {
            obj.nextSibling.style.display='block';//不把持FF
        }
        else
        {
            obj.nextSibling.nextSibling.style.display='block';
        }
    }
}
//搜索函数
var doSearch = function()
{
    //搜索的关键字
    var keyvalue = document.getElementById('SeachKeyWord').value;
    
    if(/^[a-zA-Z0-9\u4e00-\u9fa5]{2,30}$/.test(keyvalue))
    {
        if(keyvalue=='')
        {
            alert('请您输入要查找的内容！');
            return;
        }
        if(keyvalue.indexOf('-')>0)
        {
		    var regexp = new RegExp("-",'gi'); 
            keyvalue = keyvalue.replace(regexp,' ');
        }
        if(keyvalue.indexOf('#')>-1)
        {
            var regexp = new RegExp("#",'gi'); 
            keyvalue = keyvalue.replace(regexp,'');
        }
        if(keyvalue.indexOf('@')>-1)
        {
            var regexp = new RegExp("@",'gi'); 
            keyvalue = keyvalue.replace(regexp,'');
        }
        if(keyvalue.indexOf('\'')>-1)
        {
            var regexp = new RegExp("\'",'gi'); 
            keyvalue = keyvalue.replace(regexp,'');
        }
        if(keyvalue.length<2)
        {
            alert('查找的内容不能少于两个字符');
            $('#SeachKeyWord').val('');
            return;
        }
       // alert(keyvalue);
        location.href = "http://shopping.vancl.com/Product/ProductSearch/-1-------"+encodeURI(keyvalue)+".html"; //类别-排序类型-记录数-页次-页大小-关键字
        return;
    }
}
//按下回车搜索
var keyUpdo = function(e)
{
    if(e.keyCode==13)
    {
        doSearch();        
    }    
}
var ChooseSize = function(productid)
{
   $('#ajax_fastview > .main').html('<img src=\"http://images.vancl.com/logo/loading.gif\" alt=\"loading\" />');
     $.blockUI({ 
            message: $('#ajax_fastview'), css: { 
                top:  ($(window).height()-300) /2 + 'px', 
                left: ($(window).width()-512) /2 + 'px',
                width: '512px',height: '374px' ,
                cursor: 'text'
            }
      });
      var UpStr = "ProductCode="+escape(productid);  
            // update the block message 
            $.ajax({ 
                url: '/Product/ProductInfo.ashx?'+UpStr, 
                cache: false, 
                datatype: "json",
                contentType: "application/json",
                success: function(data, textStatus) {                    
                    var json = eval("("+data+")");      
                    var tempImgUrl1 = "http://images.vancl.com/Product/";         
                    var tempImgUrl = tempImgUrl1+productid.substr(0,1)+"/"+productid.substr(1,1)+"/"+productid.substr(2,1)+"/"+productid +"/";
                    var tempStr = "<div class=\"prodimg\">";
			            tempStr += "            <p class=\"mainimg\"><a href=\"#\"><img src=\"" + tempImgUrl + "middle/" + json.ImgPath.ImgPath1 + "\" alt=\""+json.ProductInfo.ProductName+"\" height=\"222\" width=\"162\" onerror=\"ErrorImg(this,0)\" id=\"productImage\" /></a></p>";
			            tempStr += "            <p class=\"viewbig\"><a href=\"/Product/Pic.aspx?ProductCode="+productid+"&ProductName="+escape(json.ProductInfo.ProductName)+"\" target=\"_blank\"\">观看清晰图片</a></p>";
			            tempStr += "            <ul class=\"album\" style=\"cursor:pointer;\">";
			            if(typeof(json.ImgPath.ImgPath1) == 'string')
			            {
				            tempStr += "                <li><img onerror=\"ErrorImg(this,1)\" src=\"" + tempImgUrl + "small/" + json.ImgPath.ImgPath1 + "\" alt=\""+json.ProductInfo.ProductName+"\" style=\"width:52px;height:52px;\" onclick=\"AlternatePhoto(this)\" /></li>";
			            }	        
			            if(typeof(json.ImgPath.ImgPath2) == 'string')
			            {       
				            tempStr += "                <li style='margin-left:5px;'><img onerror=\"ErrorImg(this,1)\" src=\"" + tempImgUrl + "small/" + json.ImgPath.ImgPath2 + "\" alt=\""+json.ProductInfo.ProductName+"\" style=\"width:52px;height:52px;\" onclick=\"AlternatePhoto(this)\" /></li>";
			            }	    
			            if(typeof(json.ImgPath.ImgPath3) == 'string')
			            {    
				            tempStr += "                <li style='margin-left:5px;'><img onerror=\"ErrorImg(this,1)\" src=\"" + tempImgUrl + "small/" + json.ImgPath.ImgPath3 + "\" alt=\""+json.ProductInfo.ProductName+"\" style=\"width:52px;height:52px;\" onclick=\"AlternatePhoto(this)\" /></li>";
			            }	        
			            tempStr += "            </ul>";
		                tempStr += "        </div>";
		                tempStr += "        <div class=\"prodattr\">";
			            tempStr += "            <h4 id=\"t_ProName\">"+json.ProductInfo.ProductName+"</h4>";
			            tempStr += "            <p class=\"price\">原价："+json.ProductInfo.VPrice+" 现价："+json.ProductInfo.Price+"</p>";
			            tempStr += "            <p class=\"detail\">"+json.ProductInfo.Intro+"</p>";
			            tempStr += "            <p class=\"colors\">";
			            var i = 0;
			            var tempImgPro = "";
			            while(typeof(json.ColorList[i])=='object')
			            {
			                if(i==13)
			                {
			                    tempStr += "<img src=\" http://images.vancl.com/Others/moreColor.gif\" alt=\"更多\" style=\"width:30px;height:30px; cursor:pointer;margin-left:3px;border:0;\" onclick=\"$.unblockUI();\" />";
			                    break;
			                }
			                else
			                {
			                    tempImgPro = json.ColorList[i].ProductCode;
			                    tempStr += "<img src=\""+tempImgUrl1+tempImgPro.substr(0,1)+"/"+tempImgPro.substr(1,1)+"/"+tempImgPro.substr(2,1)+"/"+tempImgPro.substr(0,6) +"/"+json.ColorList[i].Url+"\" alt=\"\" onclick=\"ChooseSize('"+tempImgPro+"')\" style=\"width:28px;height:28px; cursor:pointer;margin-left:3px;border:1px solid #336699;\" />";
			                    i++;  
			                }       
			            }
			            tempStr += "         </p>";
			            tempStr += "            <dl class=\"size\">";
				        tempStr += "                <dt>尺寸：<span id=\"sizeSpan1\">未选择</span></dt>";
				        i=0;
				        while(typeof(json.ProProperty[i])=='object')
				        {
				            tempStr += "                <dd onclick=\"chooseTheSize(this,'"+json.ProProperty[i].ClothesCode+"',"+json.ProProperty[i].ForOrder+")\" style=\"cursor:pointer;\">"+json.ProProperty[i].CSize+"</dd>";
				            i++;            
				        }
			            tempStr += "            </dl><br />";
			            tempStr += "            <p class=\"tocart\">数量：<select id=\"BuyNum\" style=\"width:42px;\">";
						tempStr += "		    <option value=\"1\">1</option>";
						tempStr += "	    </select>  <a href=\"#\"><img src=\"http://images.vancl.com/shopping/btn_cart.png\" alt=\"放入购物车\" id=\"yes1\" border=\"0\" onclick=\"NoSizeFun();\" /></a></p>";
		                 tempStr += "       </div>";
                    $('#ajax_fastview > .main').html(tempStr);
                     if(i==1)
                     {
                          $('#ajax_fastview > .main> .prodattr> .size dd').eq(0).click();
                     }
                },
                error: function()
                {
                     $.blockUI({ message: "<h3>出现服务器错误,管理员会解决这个问题的！</h3><div style=\"width:100%; text-align:center;\"><input type=\"button\" value=\" 确定 \" onclick=\"$.unblockUI();\" ></div>",css:{ width: '400px',height: '120px', textAlign: 'left' } }); 
                }
            }); 
 
        $('#no').click(function() { 
            $.unblockUI(); 
            $('#ajax_fastview > .main').html("");
            return false; 
        }); 
}
//放入购物车
//var AddToCart = function(productCodeS)
//{
//    var urlStr = '/Shopping/Product_Add.aspx?ProductID='+productCodeS+'&num='+document.getElementById("BuyNum").value;
//    window.location.href = urlStr;
//}
//更换排序方式
var ChangeOrderType = function(obj)
{
    var tempUrl = window.location.href;
    var arrParam = tempUrl.split('-');
    if(arrParam.length==6)
    {
        arrParam[1]=obj.value;
        var str = "";
        for(var i=0;i<arrParam.length;i++)
        {
            str += arrParam[i];
            if(i!=(arrParam.length-1))
            {
                str += "-";
            }
        }
        window.location.href = str;
    }
}
//图片不存在时
//                      图片对象,图片类型
var ErrorImg = function(obj,imgtype)
{ 
    var imgname = "";
    switch(imgtype)
    {
        case 0:
            imgname = 'm_NoPic.gif';
            break;
        case 1:
            imgname = 's_NoPic.gif';
            break;
        case 2:
            imgname = 'l_noPic.gif';
            break;
    }
    obj.src = "http://images.vancl.com/noPic/"+imgname;
}

var NoSizeFun = function()
{
    alert('请选择尺寸');
    return false;
}
function Add(f,p,u,mark)
{
    //正常的属性选择
    if(mark==0)
    {
        var carray=new Array();
        var parray=new Array();
    
        var a=document.getElementById("CADD");
        //var str=document.getElementById("Cate");
        var d=document.getElementById("CPDD");
        //是否存在同样的属性值
        var existca=false;
        //是否需要提交
        var UserOp=false;
        //是否该属性已经被选择
        var existcp=false;

        if(a.value=="")
        {
            a.value=f;
            //str.innerHTML=p;
            UserOp=true;
            d.value=u;
        }
        else
        {
            //判断是否存在同样的属性选择
            parray=d.value.split("|");
            for(var i=0;i<parray.length;i++)
            {
                if(parray[i].toString()==u.toString())
                {
                    existcp=true;
                    break;
                }
            }
            //判断是否存在同样的属性值
            carray=a.value.split("|");
            for(var j=0;j<carray.length;j++)
            {
                if(carray[j].toString()==f)
                {
                    existca=true;
                    break;
                }
            }
            //不存在同属性的同属性值
            if(!existca&&!existcp)
            {
                    a.value=a.value+'|'+f;
                    //str.innerHTML=str.innerHTML+','+p;
                    d.value=d.value+'|'+u;
                    UserOp=true;
            }
            if(!existca&&existcp)
            {
                var samecc="";
                var darray=new Array();
                darray=document.getElementsByName(u);
             
                for(var k=0;k<darray.length;k++)
                {
                    for(var n=0;n<carray.length;n++)
                    {
                        if(darray[k].id==carray[n].toString())
                        {
                            //samecc=carray[n].toString();
                            samecc=n;
                            break;
                        }
                    }
                }
                if(samecc==carray.length)
                {
                    a.value='';
                    for(var m=0;m<carray.length;m++)
                    {
                        if(m!=samecc)
                        {
                            if(a.value=='')
                            {
                                a.value=carray[m].toString();
                            }else
                            {
                                a.value=a.value+'|'+carray[m].toString();
                            }
                        }
                        else
                        {
                            if(a.value=='')
                            {
                                a.value=f;
                            }else
                            {
                                a.value=a.value+'|'+f;
                            }
                        }
                    }
                }
                else
                {
                    a.value='';
                    for(var v=0;v<samecc;v++)
                    {
                        if(a.value=='')
                        {
                            a.value=carray[v].toString();
                        }else
                        {
                            a.value=a.value+'|'+carray[v].toString();
                        }
                    }
                    if(a.value=='')
                    {
                        a.value=f;
                    }else
                    {
                        a.value=a.value+'|'+f;
                    }
                }
                //a.value=a.value+'|'+f;

                UserOp=true;
            }
        }
        //有必要提交
        if(UserOp)
        {
//            document.form1.action=checkUrl();
//            document.form1.submit();
                checkUrl();
        }
    }
    if(mark==1)
    {
        //类别属性列选择
        var catearray=new Array();
        var pcidarray=new Array();
        var ca=document.getElementById("CADD");
        catearray=ca.value.split('|');
        var mindex=0;
        var newca="";
        for(var i=0;i<catearray.length;i++)
        {
            if(catearray[i].toString()==f.toString())
            {
                mindex=i;
                break;
            }
        }
        for(var l=0;l<=mindex;l++)
        {
            if(newca=="")
            {
                newca=catearray[l].toString();
            }
            else
            {
                newca=newca+'|'+catearray[l].toString();
            }
        }
        ca.value=newca;
        
        //Url处理
//        document.form1.action=checkUrl();
//        document.form1.submit();
        checkUrl();
    }
}
function checkUrl()
{
	var acurl=location.href;
	var m=acurl.indexOf('-');
	var k=acurl.lastIndexOf('/');
	var s1=acurl.substring(k+1,m);

	var toUrl= 'Product/ProductList/'+s1+'-1-------.html';
	//alert(toUrl);
	navto(toUrl);
}
function ChangeOrderTypeA(obj)
{
//    var o=document.getElementById("ORDERTYPEA");

//    if(obj.value!=0)
//    {
//        o.value=obj.value;
//    }
//    document.form1.submit();
    location.href="http://shopping.vancl.com/Product/ProductList/"+obj.value.toString()+".html";
}
function ChangeOrderTypeB(obj)
{
    location.href="http://shopping.vancl.com/Product/ProductSearch/"+obj.value.toString()+".html";
}

function ChangeOrderTypeC(obj)
{
   location.href="/Product_CommentList-"+obj.value.toString()+".html";
}
function navto(url)
{
    var f = document.createElement("form");
    document.body.appendChild(f);
    
    var ca = document.createElement("input");
    ca.type = "hidden";
    f.appendChild(ca);
    ca.value = document.getElementById("CADD").value;
    ca.name = "CADD";
        
    var pa = document.createElement("input");
    pa.type = "hidden";
    f.appendChild(pa);
    pa.value = document.getElementById("CPDD").value;
    pa.name = "CPDD";

    f.method = "post";
    f.action = "http://shopping.vancl.com/"+url;
    f.submit();
}
function searchByPrice(minp,maxp)
{
    /* 价格搜索：判断价格是否都是正数
    */
    var urlBase="";
    var NowUrl=location.href;
    var Params=new Array();
    Params=NowUrl.split('-');
    var innerMaxp=0;
    var innerMinp=0;
    if(Params.length!=9)
    {
        NowUrl="http://shopping.vancl.com/Product/ProductSearch/-1-------.html";
        Params=NowUrl.split('-');
    }

    if(minp==null||minp==""||minp<0)
    {
        innerMinp=0;
    }
    else
    {
        innerMinp=minp;
    }
    if(maxp==null||maxp==""||maxp<0)
    {
        innerMaxp=1000;
    }
    else
    {
        innerMaxp=maxp;
    }
 
    if(innerMinp<innerMaxp)
    {
        for(var i=0;i<Params.length;i++)
        {
            if(i==6)
            {
                if(minp!=null&&minp!=""&&minp>0)
                {
                    urlBase=urlBase+'-'+minp;
                    continue;
                }
                else
                {
                    urlBase=urlBase+'-';
                    continue;
                }
            }
            if(i==7)
            {
                if(maxp!=null&&maxp!=""&&maxp>0&&innerMaxp!=1000)
                {
                    urlBase=urlBase+'-'+maxp;
                    continue;
                }
                else
                {
                    urlBase=urlBase+'-';
                    continue;
                }
            }
            if(i==1)
            {
                urlBase=urlBase+'-1';
                continue;
            }
            if(i==0)
            {
                urlBase=Params[0];
                continue;
            }
            urlBase=urlBase+'-'+Params[i];
        }
        location.href=urlBase;
    }
}

